<?php
defined('IN_TS') or die('Access Denied.');
class plan extends tsApp{

	//构造函数
	public function __construct($db){
		parent::__construct($db);
	}
	
	//通过topicid获取方案基本信息
	function getPlanByPlanid($planid){
		$strPlan = $this->db->once_fetch_assoc("select * from ".dbprefix."plan where planid='$planid'");
		
		//成员
		$strPlan['user'] = $this->db->once_fetch_assoc("select * from ".dbprefix."user_info where userid='".$strPlan['userid']."'");
		
		//时间
		$weekarray=array("周日","周一","周二","周三","周四","周五","周六");  
		
		$strPlan['time_start'] = date('Y',strtotime($strPlan['time_start'])).'年'.date('m',strtotime($strPlan['time_start'])).'月'.date('d',strtotime($strPlan['time_start'])).'日 '.$weekarray[date("w",strtotime($strPlan['time_start']))].' '.date('H:i',strtotime($strPlan['time_start']));
		
		$strPlan['time_end'] = date('Y',strtotime($strPlan['time_end'])).'年'.date('m',strtotime($strPlan['time_end'])).'月'.date('d',strtotime($strPlan['time_end'])).'日 '.$weekarray[date("w",strtotime($strPlan['time_end']))].' '.date('H:i',strtotime($strPlan['time_end']));
		
		//地点
		//$strPlan['area'] = aac('location')->getAreaForApp($strPlan['areaid']);
		
		//方案类型
		$strPlan['type'] = $this->db->once_fetch_assoc("select * from ".dbprefix."plan_type where typeid='".$strPlan['typeid']."'");
		
		return $strPlan;
	}
	
	//
	function getSimplePlan($planid){
		$strPlan = $this->db->once_fetch_assoc("select * from ".dbprefix."plan where planid='$planid'");
		
		//地点
		//$strPlan['area'] = aac('location')->getAreaForApp($strPlan['areaid']);
		
		//成员
		$strPlan['user'] = $this->db->once_fetch_assoc("select * from ".dbprefix."user_info where userid='".$strPlan['userid']."'");

	}

	
	/*
	 *获取内容评论列表
	 */
	
	function getPlanComment($page = 1, $prePageNum,$planid){
		$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
		$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
		$arrGroupContentComment	= $this->db->fetch_all_assoc("select * from ".dbprefix."plan_comment where planid='$planid' order by addtime desc $limit");
		
		if(is_array($arrGroupContentComment)){
			foreach($arrGroupContentComment as $key=>$item){
				//$arrGroupContentComment[$key]['user'] = $this->getUserData($item['userid']);
				$arrGroupContentComment[$key]['user'] = aac('user')->getOneUser($item['userid']);
				$arrGroupContentComment[$key]['content'] = hview($item['content']);
			}
		}
		
		return $arrGroupContentComment;
	}
	
	/*
	 *获取内容评论列表数
	 */
	
	function getPlanCommentNum($virtue, $setvirtue){
		$where = 'where '.$virtue.'='.$setvirtue.'';
		$res = "SELECT * FROM ".dbprefix."plan_comment $where";
		$groupContentCommentNum = $this->db->once_num_rows($res);
		return $groupContentCommentNum;
	}
	
	//获取方案小组
	function getGroup($groupid){
		$strGroup = $this->db->once_fetch_assoc("select * from ".dbprefix."app_group where groupid='$groupid'");
		if($strGroup['groupicon'] == ''){
			$strGroup['groupicon'] = 'uploadfile/group/default/default.gif';
		}
		return $strGroup;
	}

	//获取方案类型
	function getType($typeid){
		$strType = $this->db->once_fetch_assoc("select * from ".dbprefix."plan_type where typeid='".$typeid."'");

		return $strType;
	}


}